package com.ep.appupdatedemo.update;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by Administrator on 2017/8/8.
 */

public class AppUtils {

    /**
     * 获取App版本号
     * @return App版本号
     */
    public static String getAppVersionName(Context context) {

        try {
            String packageName=context.getApplicationContext().getPackageName();
            PackageManager pm = context.getApplicationContext().getPackageManager();
            PackageInfo pi = pm.getPackageInfo(packageName, 0);
            return pi == null ? null : pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
}
